package com.mystore.framework.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mystore.framework.mapper.UriMapper;
import com.mystore.framework.pojo.App;
import com.mystore.framework.pojo.AppModel;
import com.mystore.framework.pojo.Uri;
import icu.mhb.mybatisplus.plugln.base.mapper.JoinBaseMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

@Service
public class IUriServiceImpl extends IBaseServiceImpl<UriMapper,Uri>{
    @Transactional
    public int insertOne(Uri t) {
        return baseMapper.insert(t)==0?0:t.getUriId();
    }
    @Override
    public IPage<Uri> selectPageByData(String data, Page<Uri> page) {
        QueryWrapper<Uri> queryWrapper=new QueryWrapper<>();
        queryWrapper.apply("(CONCAT_WS('-',uri_id,uri_location)) like {0}","%"+data+"%");
        return baseMapper.selectPage(page,queryWrapper);
    }
    public Set<Uri> selectUrisByIds(Set<String> ids){
        if (ids==null||ids.isEmpty())
            return null;
        TreeSet<Uri> uriTreeSet=new TreeSet<>();
        ids.forEach(id->{uriTreeSet.add(baseMapper.selectOne(new QueryWrapper<Uri>().eq("uri_id",id)));});
        return uriTreeSet;
    }
}
